<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        .login-container {
            background-color: #fff;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
        }
        .login-container h2 {
            margin-top: 0;
            text-align: center;
        }
        .login-container input[type="text"],
        .login-container input[type="password"] {
            width: 100%;
            padding: 0.5rem;
            margin: 0.5rem 0;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .login-container input[type="submit"] {
            width: 100%;
            padding: 0.75rem;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 1rem;
        }
        .login-container input[type="submit"]:hover {
            background-color: #45a049;
        }
        .login-container .error {
            color: red;
            text-align: center;
            margin-top: 0.5rem;
        }
    </style>
</head>
<body>

<div class="login-container">
    <h2>登录</h2>
    <form action="/login" method="post">
        <input type="text" id="username" name="username" placeholder="用户名" required>
        <input type="password" id="password" name="password" placeholder="密码" required>
        <input type="submit" value="登录">
        <div class="error" id="error-message"></div>
    </form>
    <p>没有账户？ <a href="/register">注册</a></p>
</div>

<script>
    // 示例脚本：在提交表单前显示错误消息（实际中应由后端处理）
    document.querySelector('form').addEventListener('submit', function(event) {
        // 这里只是为了演示，实际中应该移除或注释掉这部分代码
        event.preventDefault(); // 阻止表单提交
        var errorMessage = document.getElementById('error-message');
        errorMessage.textContent = '这是一个示例错误消息。在实际应用中，这个错误应由后端验证后返回。';
        errorMessage.style.display = 'block'; // 显示错误消息
    });
</script>

</body>
</html>